home *** CD-ROM | disk | FTP | other *** search
- /*
- main.c
-
- A very simple app to show you how SmartDragWindow() works.
-
- Written by Hiep Dam
- From The Witches' Brew
- Dec 2 95
-
- Public domain give-away-ware.
- I've learned a lot from all the source code people made available
- out there. This is my thanks back to everyone.
-
- Version History
- Nov 6 95: Created.
- Dec 2 95: Added MySnapProc.
- */
-
- #include "InitToolbox.h"
- #include "SmartDragWindow.h"
-
- void EventLoop();
- void MySnapProc(WindowPtr windowToDrag, short snapToDistance, Rect *snapRect);
- void DrawGrowIconNoLines(WindowPtr wp, Boolean hideLines);
-
- // ---------------------------------------------------------------------------
-
- void main() {
- WindowPtr theWindow;
- Rect windowBounds;
- short i;
-
- InitToolbox();
-
- windowBounds = (**GetMainDevice()).gdRect;
- windowBounds.right = windowBounds.left + 350;
- windowBounds.bottom = windowBounds.top + 120;
-
- for (i = 0; i < 3; i++) {
- OffsetRect(&windowBounds, 20, 50);
- theWindow = NewWindow(NULL, &windowBounds,
- "\pSmartDragWindow Demo", true,
- documentProc, (WindowPtr)-1, true, 0);
- SetPort(theWindow);
- TextFont(geneva);
- TextSize(9);
- }
-
- EventLoop();
- } // END main
-
- // ---------------------------------------------------------------------------
-
- void EventLoop() {
- EventRecord theEvent;
- short part;
- WindowPtr theWindow;
- Boolean done = false;
-
- while (!done)
- if (WaitNextEvent(everyEvent, &theEvent, 50, NULL)) {
- switch(theEvent.what) {
- case mouseDown:
- part = FindWindow(theEvent.where, &theWindow);
-
- switch(part) {
- case inDrag: {
- // Aah. Our routine!
- // Give it a large snap-to-distance
- // to make it obvious...
- SuperSmartDragWindow(theWindow, theEvent.where, NULL, 25, MySnapProc);
-
- // Use the below for default dragging (snap to monitors only)
- //SmartDragWindow(theWindow, 20, NULL);
- } break;
-
- case inGrow: {
- Rect sizeRect = { 40, 40, 400, 400 };
- long lSizeVH;
-
- lSizeVH = GrowWindow(theWindow, theEvent.where, &sizeRect);
- SizeWindow(theWindow,LoWord(lSizeVH),HiWord(lSizeVH),false);
- InvalRect(&theWindow->portRect);
- } break;
-
- case inGoAway:
- if (TrackGoAway(theWindow, theEvent.where)) {
- DisposeWindow(theWindow);
- if (FrontWindow() == NULL)
- done = true;
- }
- break;
-
- case inContent:
- if (FrontWindow() != theWindow)
- SelectWindow(theWindow);
- else
- SysBeep(10);
- break;
- }
- break; // mouseDown
-
- case keyDown:
- done = true;
- break;
-
- case updateEvt: {
- WindowPtr theWindow;
- GrafPtr savePort;
-
- theWindow = (WindowPtr)theEvent.message;
- GetPort(&savePort);
- SetPort(theWindow);
-
- BeginUpdate(theWindow);
- EraseRect(&theWindow->portRect);
- DrawGrowIconNoLines(theWindow, true);
- TextFace(bold);
- MoveTo(10, 25);
- DrawString("\pSmartDragWindow by Hiep Dam.");
- TextFace(0);
- DrawString("\p From The Witches' Brew 1995");
- MoveTo(20, 50);
- DrawString("\pWatch the windows snap to the edge of the monitor and to");
- MoveTo(20, 65);
- DrawString("\pother windows as you drag.");
- MoveTo(20, 80);
- DrawString("\pTry dragging non-frontmost windows as well (using the cmd-key).");
- EndUpdate(theWindow);
- } break;
-
- case activateEvt:
- break;
- }
- }
- } // END EventLoop
-
- // ---------------------------------------------------------------------------
-
- void MySnapProc(WindowPtr windowToDrag, short snapToDistance, Rect *snapRect) {
- WindowSnapProc(windowToDrag, snapToDistance, snapRect);
- MonitorSnapProc(windowToDrag, snapToDistance, snapRect);
- } // END MySnapProc
-
- // ---------------------------------------------------------------------------
-
- #define kGrowBoxSize 16
-
- void DrawGrowIconNoLines(WindowPtr wp, Boolean hideLines) {
- RgnHandle saveClip;
- GrafPtr savePort;
- Rect growBox;
-
- if( hideLines == false ){
- DrawGrowIcon( wp );
- }else{
- saveClip = NewRgn();
- if( saveClip == NULL )
- return;
-
- GetPort( &savePort );
- SetPort( wp );
-
- GetClip( saveClip );
-
- growBox.right = wp->portRect.right;
- growBox.bottom = wp->portRect.bottom;
- growBox.left = growBox.right - kGrowBoxSize;
- growBox.top = growBox.bottom - kGrowBoxSize;
-
- ClipRect( &growBox );
- DrawGrowIcon( wp );
-
- SetClip( saveClip );
- SetPort( savePort );
- DisposeRgn( saveClip );
- }
- } // DragGrowIconNoLines